package com.starinside.wp.repository;

import com.starinside.wp.foundation.vo.ChildrenEvoluateRecordVO;
import com.starinside.wp.foundation.vo.ChildrenHealthBaseInfoVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class HealthBaseInfoNativeRepository extends BaseNativeSqlRepository{


    /**
     */
    public List<ChildrenHealthBaseInfoVO> findVOByChildrenId(String childrenId, String beforeTime, String afterTime){
        String sql = "SELECT id,month,gestationalAge,childrenId,teacherId,evaluateTime,created,evaluateName " +
                "from children_health_base_info a " +
                "where a.childrenId ='%s' and created<'%s' " +
                (StringUtils.isEmpty(afterTime) ? "" : String.format("and a.created>'%s' ", afterTime)) +
                "order by created desc";

        sql =  String.format(sql, childrenId, beforeTime);

        List<ChildrenHealthBaseInfoVO> items = sqlObjectList(sql, ChildrenHealthBaseInfoVO.class);

        return items;
    }
}
